using System.Threading;

namespace Beetle;

public abstract class CounterMessage : ICounterMessage
{
	private int a;

	public void SetCount(int count)
	{
		a = count;
	}

	public void Decrement()
	{
		if (Interlocked.Decrement(ref a) == 0)
		{
			Recover();
		}
	}

	protected abstract void Recover();

	public abstract void Save(IDataWriter writer);

	public abstract void Load(IDataReader reader);
}
